package com.hxzy.es.controller;

import com.baizhi.common.enums.AckCode;
import com.baizhi.common.vo.R;
import com.hxzy.dto.GoodsInfoSearch;
import com.hxzy.es.entity.EsGoodsInfo;
import com.hxzy.es.service.EsGoodsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/es/goods")
public class EsGoodsInfoController {

    @Autowired
    private EsGoodsInfoService esGoodsInfoService;

    @GetMapping(value = "/price")
    public R  findBySellingPrice(int min,int max){
        List<EsGoodsInfo> bySellingPrice = this.esGoodsInfoService.findBySellingPrice(min, max);
        return R.okHasData(bySellingPrice);
    }

    @GetMapping(value = "/{id}")
    public R findById(@PathVariable(value = "id") Long id){
        EsGoodsInfo byId = this.esGoodsInfoService.findById(id);

        if(byId==null){
            return R.build(AckCode.NOT_FOUND_DATA);
        }
        return R.okHasData(byId);
    }

    @GetMapping(value = "/search")
    public R search(GoodsInfoSearch goodsInfoSearch){

        return R.okHasData(this.esGoodsInfoService.search(goodsInfoSearch));

    }
}
